package com.disdr;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;

public class SHA1Example {

    public static void main(String[] args) {
        Long lll = new Date().getTime()/10000;
        System.out.println(System.currentTimeMillis());

        String input = "welara_api_permission"+lll;

        try {
            MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
            byte[] hash = sha1.digest(input.getBytes(StandardCharsets.UTF_8));

            StringBuilder hexString = new StringBuilder();
            for (byte b : hash) {
                String hex = Integer.toHexString(b & 0xff);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }
            //cd23ecfa593cca2b4de3870834d184d87398e50a
            System.out.println("SHA-1 hash: " + hexString);
            System.out.println("SHA-1 hash: " + hexString.toString());
            System.out.println(lll);
        } catch (NoSuchAlgorithmException e) {
            System.out.println("SHA-1 algorithm not found.");
        }
    }

}
